﻿<Window x:Class="XmlStudio.Dialogs.EditXmlElementDialog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        loc:Translate.Uid="EditXmlElementDialog.WindowTitle"
        xmlns:reg="clr-namespace:XmlStudio.Validators"
        xmlns:userControls="clr-namespace:XmlStudio.Resources.UserControls" 
        xmlns:loc="clr-namespace:Tomers.WPF.Localization;assembly=Tomers.WPF.Localization" 
        Title="{loc:Translate 'Edit XmlElement'}"
        MinWidth="200"
        MinHeight="150"
        WindowStartupLocation="CenterOwner"
        ResizeMode="CanResizeWithGrip"
        x:Name="EditXmlElementWindow"
        Style="{StaticResource XmlStudioDialogStyle}">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/XmlStudio;Component/Resources/GraphResources.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <!-- This style allows a validation error message to be displayed in a TextBox's tooltip. -->
            <Style TargetType="{x:Type TextBox}">
                <Setter Property="Margin" Value="0,8" />
                <Style.Triggers>
                    <Trigger Property="Validation.HasError" Value="True">
                        <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </ResourceDictionary>
    </Window.Resources>
    <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
        <Border BorderBrush="Gray" BorderThickness="1" Margin="{StaticResource DialogBoxMargin}" Background="{StaticResource DialogBackgoundBrush}">
            <Grid Margin="{StaticResource DialogBoxMargin}" >

                <Grid.RowDefinitions>
                    <RowDefinition Height="{StaticResource GridRowHeight}" />
                    <RowDefinition Height="{StaticResource GridRowHeight}" />
                    <RowDefinition Height="{StaticResource GridRowHeight}" />
                    <RowDefinition Height="{StaticResource GridRowHeight}" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="30*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <TextBlock Height="{StaticResource TextBlockHeight}" Grid.Row="0" x:Name="prefixTextBlock" 
                           loc:Translate.Uid="EditXmlElementDialog.prefixTextBlock" Text="{loc:Translate Prefix:}" />
                <TextBlock Height="{StaticResource TextBlockHeight}" Grid.Row="1" x:Name="localNameTextBlock" 
                           loc:Translate.Uid="EditXmlElementDialog.localNameTextBlock" Text="{loc:Translate LocalName:}" />
                <TextBlock Height="{StaticResource TextBlockHeight}" Grid.Row="2" x:Name="namespaceURITextBlock" 
                           loc:Translate.Uid="EditXmlElementDialog.namespaceURITextBlock" Text="{loc:Translate NamespaceURI:}" />
                <TextBlock Height="{StaticResource TextBlockHeight}" Grid.Row="3" Grid.ColumnSpan="2" 
                           loc:Translate.Uid="EditXmlElementDialog.Attributes" Text="{loc:Translate Attributes:}" />

                <TextBox Margin="{StaticResource TextBoxMargin}" Height="{StaticResource TextBoxHeight}" MinWidth="157" Grid.Column="1" Grid.Row="0" x:Name="prefixTextBox">
                    <TextBox.Text>
                        <Binding Path="Element.Prefix" UpdateSourceTrigger="Explicit">
                            <Binding.ValidationRules>
                                <reg:XmlValidationRule ValidationOptions="Prefix" />
                            </Binding.ValidationRules>
                        </Binding>
                    </TextBox.Text>
                </TextBox>
                <TextBox Margin="{StaticResource TextBoxMargin}" Height="{StaticResource TextBoxHeight}" MinWidth="157" Grid.Column="1" Grid.Row="1" x:Name="localNameTextBox">
                    <TextBox.Text>
                        <Binding Path="Element.LocalName" UpdateSourceTrigger="Explicit">
                            <Binding.ValidationRules>
                                <reg:XmlValidationRule ValidationOptions="Element" />
                            </Binding.ValidationRules>
                        </Binding>
                    </TextBox.Text>
                </TextBox>
                <TextBox Margin="{StaticResource TextBoxMargin}" Height="{StaticResource TextBoxHeight}" MinWidth="157" Grid.Column="1" Grid.Row="2" x:Name="namespaceURITextBox">
                    <TextBox.Text>
                        <Binding Path="Element.NamespaceURI" UpdateSourceTrigger="Explicit">
                            <Binding.ValidationRules>
                                <reg:XmlValidationRule ValidationOptions="NamespaceUri" />
                            </Binding.ValidationRules>
                        </Binding>
                    </TextBox.Text>
                </TextBox>
                <userControls:UcAttributes x:Name="ucAttributes" ItemTemplate="{StaticResource XmlAttributeViewModelTemplate}" ReadOnly="False" 
                                           Attributes="{Binding ElementName=EditXmlElementWindow, Path=Attributes, Mode=TwoWay, UpdateSourceTrigger=Explicit}" 
                                           Grid.Row="4" Grid.ColumnSpan="2" Margin="0 3 0 0" />

                <userControls:OKCancelButtons OKClicked="Button_Click" Margin="0 7 0 0" Grid.Row="5" Grid.ColumnSpan="2" />
            </Grid>
        </Border>
    </ScrollViewer>
</Window>
